package com.ifnk.portaljava.dapWeb.socket;
/**
 * <p>Title: 向proxy写命令类</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2010</p>
 *
 * <p>Company: </p>
 *
 * @author WenSheng.Song.hlyt@gmail.com
 * @version 1.0
 */

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.IOException;
import java.io.OutputStream;

public class SocketWriter extends Thread {
	private OutputStream out;
	private byte[] data;
	private int len;
	private boolean error = true;
	private Log loger = LogFactory.getLog(SocketWriter.class);

	public OutputStream getOut() {
		return out;
	}

	public void setOut(OutputStream out) {
		this.out = out;
	}

	public int getLen() {
		return len;
	}

	public void setLen(int len) {
		this.len = len;
	}

	public boolean isError() {
		return error;
	}

	public void setError(boolean error) {
		this.error = error;
	}

	public SocketWriter(OutputStream out, byte[] data, int len) {
		super();
		this.out = out;
		this.data = data;
		this.len = len;
	}

	public void run() {
		try {
			if (out != null) {
				out.write(data, 0, len);
				out.flush();
				this.error = true;
			}
		} catch (IOException e) {
			this.error = false;
			loger.error("WebServer Exception " + e.toString());
		}
	}
}
